home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright Cornell University 1986. All rights are reserved.
- */
-
- #include <em.h>
- #include <memory.h>
-
- /* Here follow general purpose buffer mod routines for deleting, scrolling,
- etc. */
-
- /* Delete a line at the line # specified in the call
- calculate scrolling regions if vt100 being used
- */
-
- short usedsdraw; /* OK to use direct to screen drawing */
- short emobscured; /* the window is partially covered, not OK to scroll */
- short emupdwait; /* waiting for update, don't show cursor or scroll */
-
- #define PROMPTUPD
-
- del_lin(lin)
- unsigned int lin;
- {
- unsigned char * srcp, * destp;
- unsigned long count;
- short bigsave;
- short bigbotsave;
-
- if (lin == emdp->lastrow) {
- /* kind of unexpected parameter, don't try to scroll! */
- modflg |= modmask[lin];
- c19_blank(emdp->lastline, (int) linelength);
- return;
- }
- if (lin > emdp->lastrow) {
- /* bad arg */
- return;
- }
-
- if (emwindow != NULL && modflg && !emdp->vtjumpscroll) {
- /* !(|| emdp->selrectvis || bkrd_act)) emdp->color ||
- refresh the screen image first */
-
- if (usedsdraw)
- emrefresh(emwindow, TRUE);
- else
- (*emdp->screen_upd)();
- }
- /* fix the screen map */
- srcp = emdp->charr + ((lin + 1) * linelength);
- destp = srcp - linelength;
- if (mode == VT100MODE) {
- count = (emdp->scrollbottom - lin) * linelength;
- }
- else {
- count = emdp->charrend - srcp;
- }
-
- if (!emdp->ibm_keymode)
- saveline(destp, linelength);
- /* save the line if needed before it gets overwritten;
- makes logging scrolling region-based help work swell... */
-
- BlockMove(srcp, destp, count);
- BlockMove(srcp + emdp->screensize, destp + emdp->screensize, count);
- if (mode == VT100MODE) {
- c19_blank(destp + count, (int) linelength);
- }
- else {
- c19_blank(emdp->lastline, (int) linelength);
- }
-
-
- if (emwindow != NULL) {
- /* scroll the screen image */
-
- if (emdp->vtjumpscroll) {
- /* redraw the whole screen later on */
- clrflg = 0; /* for simplicity's sake */
- while (lin <= emdp->scrollbottom )
- /* mark modified lines */
- modflg |= modmask[lin++];
- }
- else if (emdp->selrectvis || bkrd_act || emobscured) {
- /* emdp->color || redraw the whole screen using QD */
-
- clrflg = 0; /* for simplicity's sake */
- while (lin <= emdp->scrollbottom )
- /* mark modified lines */
- modflg |= modmask[lin++];
-
- /* update promptly or wait? currently we wait until another
- scroll triggers redraw, or wait until screen_service() called
- if (usedsdraw)
- emrefresh(emwindow, TRUE);
- else
- (*emdp->screen_upd)();
- */
- }
- else {
- /* we can scroll since we're in the foreground */
- if (lin == 0)
- clrflg >>= 1;
- else
- clrflg = 0;
-
- if (usedsdraw) {
- if ((emdp->scrollbottom - lin) > 0) {
- clrflg |= modmask[emdp->scrollbottom]; /* show line cleared at bottom */
- fastscroll(startarr[lin], startarr[lin + 1], emdp->scrollbottom - lin);
- }
- }
- else {
- if (mode == VT100MODE) {
- clrflg |= modmask[emdp->scrollbottom]; /* show line cleared at bottom */
- emdp->bigrect.bottom = (emdp->scrollbottom + 1) * emdp->lineheight;
- }
- else
- clrflg |= modmask[emdp->lastrow]; /* show line cleared at bottom */
-
- emdp->bigrect.top = lin * emdp->lineheight + emdp->voffset;
- ScrollRect(&emdp->bigrect, 0, -emdp->lineheight, updateRgn);
- emdp->bigrect.top = emdp->voffset;
- emdp->bigrect.bottom = emdp->bottommarg;
- if (emdp->color) {
- paintupdate();
- }
- }
- }
- }
- }
-
-
- /* Insert space for a line at the line # specified in the call */
-
- ins_lin(lin)
- short lin;
- {
- unsigned char * srcp, * destp;
- long count;
- short bigsave;
- short bigbotsave;
-
- if (lin == emdp->lastrow) {
- /* kind of unexpected */
- modflg |= modmask[lin];
- c19_blank(emdp->lastline, (int) linelength);
- return;
- }
- if (lin > emdp->lastrow) {
- /* bad arg */
- return;
- }
-
- if (emwindow != NULL && !emdp->vtjumpscroll) {
- /* !(emdp->vtjumpscroll || emdp->selrectvis || bkrd_act) emdp->color ||
- refresh the screen image first */
- if (modflg) {
- /* we're using QD & buffer's changed, update screen first */
- if (usedsdraw)
- emrefresh(emwindow, TRUE);
- else
- (*emdp->screen_upd)();
- }
- }
- /* fix the screen map */
- srcp = emdp->charr + (lin * linelength);
- destp = srcp + linelength;
- if (mode == VT100MODE)
- count = (emdp->scrollbottom - lin) * linelength;
- else
- count = emdp->charrend - destp;
- BlockMove(srcp, destp, count);
- BlockMove(srcp + emdp->screensize, destp + emdp->screensize, count);
- c19_blank(srcp, linelength);
-
- if (emwindow != NULL) {
- /* scroll the screen image */
- if (emdp->vtjumpscroll) {
- /* redraw the whole screen later on */
- clrflg = 0; /* for simplicity's sake */
- while (lin <= emdp->scrollbottom )
- /* mark modified lines */
- modflg |= modmask[lin++];
- }
- else if (emdp->selrectvis || bkrd_act || emobscured) {
- /* redraw the whole screen using QD emdp->color || */
-
- clrflg = 0; /* for simplicity's sake */
- while (lin <= emdp->scrollbottom)
- /* mark modified lines */
- modflg |= modmask[lin++];
-
- /* update promptly or wait?
- if (usedsdraw)
- emrefresh(emwindow, TRUE);
- else
- (*emdp->screen_upd)();
- */
- }
- else {
- if (lin == 0)
- clrflg <<= 1;
- else
- clrflg = 0;
- clrflg |= modmask[lin]; /* set to show line cleared */
-
- if (usedsdraw) {
- if ((emdp->scrollbottom - lin) > 0) {
- fastindex(startarr[emdp->scrollbottom],
- startarr[emdp->scrollbottom - 1], emdp->scrollbottom - lin);
- }
- }
- else {
- if (mode == VT100MODE) {
- emdp->bigrect.bottom = (emdp->scrollbottom + 1) * emdp->lineheight;
- }
-
- emdp->bigrect.top = lin * emdp->lineheight + emdp->voffset;
- ScrollRect(&emdp->bigrect, 0, emdp->lineheight, updateRgn);
- emdp->bigrect.top = emdp->voffset;
- emdp->bigrect.bottom = emdp->bottommarg;
- if (emdp->color) {
- paintupdate();
- }
- }
- }
- }
- }
-
-
- /* Clear to end of line */
-
- /* Shift line over from cursor position to make space for a new character */
-
- ins_char()
- {
- struct Rect rect;
- unsigned char * srcp;
- unsigned char * destp;
- long count;
-
- if (emwindow != NULL) {
- /* shift the line's screen image over right */
- if (!usedsdraw || emdp->selrectvis || bkrd_act || emobscured) {
- /* redraw the line using QD had emdp->color || */
-
- modflg |= modmask[ypos];
- }
- else {
- #ifdef PROMPTUPD
- if (modflg) {
- /* we're using QD & buffer's changed, update screen first */
- if (usedsdraw)
- emrefresh(emwindow, TRUE);
- else
- (*emdp->screen_upd)();
- }
- #endif
- rect.top = (ypos * emdp->lineheight) + emdp->voffset;
- rect.left = (xpos * fontwidth) + emdp->hoffset;
- rect.bottom = rect.top + emdp->lineheight;
- rect.right = emdp->rightmarg;
- ScrollRect(&rect, fontwidth, 0, updateRgn);
- if (emdp->color) {
- paintupdate();
- }
- }
- }
-
- /* fix the screen map */
- srcp = charp;
- destp = charp + 1; /* pointing at next char */
- BlockMove(srcp, destp, (long) (lastcol - xpos));
- BlockMove(srcp + emdp->screensize, destp + emdp->screensize, (long) (lastcol - xpos));
-
- *srcp = ' ';
- *(srcp + emdp->screensize) = 0; /* clear the new space */
-
- }
-
-
- /* Delete the character at the cursor position */
-
- del_char()
- {
- struct Rect rect;
- unsigned char * srcp;
- unsigned char * destp;
- long count;
-
- if (emwindow != NULL) {
- /* scroll the screen image */
- if (!usedsdraw || emdp->selrectvis || bkrd_act || emobscured) {
- /* redraw the whole screen using QD emdp->color || */
-
- modflg |= modmask[ypos];
- }
- else {
- #ifdef PROMPTUPD
- if (modflg) {
- /* we're using QD & buffer's changed, update screen first */
- if (usedsdraw)
- emrefresh(emwindow, TRUE);
- else
- (*emdp->screen_upd)();
- }
- #endif
- rect.top = ypos * emdp->lineheight + emdp->voffset;
- rect.left = (xpos * fontwidth) + emdp->hoffset;
- rect.bottom = rect.top + emdp->lineheight;
- rect.right = emdp->rightmarg;
- ScrollRect(&rect, -fontwidth, 0, updateRgn);
- if (emdp->color) {
- paintupdate();
- }
- }
- }
- /* fix the screen map */
- srcp = charp + 1; /* pointing at next char */
- destp = charp;
- count = (lastcol - xpos);
- BlockMove(srcp, destp, count);
- BlockMove(srcp + emdp->screensize, destp + emdp->screensize, count);
-
- destp += count;
- *(destp) = ' '; /* blank out the last char */
- *(destp + emdp->screensize) = 0; /* blank attibute */
-
- }
-
- /* clear line from cursor to end of line */
-
- clr_eol()
- {
- struct Rect rect;
- long count;
-
- if (emwindow != NULL) {
- if (emdp->selrectvis || bkrd_act || emupdwait || emobscured) {
- /* must redraw through upd 'emdp->color' */
- modflg |= modmask[ypos];
- }
- else {
- /* clear the screen image; can do in bkrd */
- rect.top = ypos * emdp->lineheight + emdp->voffset;
- rect.left = xpos * fontwidth + emdp->hoffset;
- rect.bottom = rect.top + emdp->lineheight;
- rect.right = emdp->rightmarg;
- clearrect(&rect);
- }
- }
- if ((emdp->logerase || xpos == 0) && !emdp->ibm_keymode )
- saveline(charp, linelength);
- /* save WHOLE line if needed before it gets overwritten */
-
- /* fix the screen map */
- c19_blank(charp, (linelength - xpos));
- }
-
-
- /* erase line up to and including cursor position */
-
- clrtocurs()
- {
- Rect temprect;
- unsigned char * srcp;
-
- if (emwindow != NULL) {
- if (emdp->selrectvis || bkrd_act || emupdwait || emobscured) {
- /* must redraw through upd emdp->color */
- modflg |= modmask[ypos];
- }
- else {
- /* erase the screen image */
- temprect.top = ypos * emdp->lineheight + emdp->voffset;
- temprect.left = emdp->hoffset;
- temprect.bottom = temprect.top + emdp->lineheight;
- temprect.right = (xpos + 1) * fontwidth + emdp->hoffset;
-
- clearrect(&temprect);
- }
- }
- /* fix the screen map */
- srcp = charp - xpos;
-
- if ((emdp->logerase || xpos == lastcol) && !emdp->ibm_keymode)
- saveline(srcp, linelength);
- /* save the line if needed before it gets overwritten */
-
- c19_blank(srcp, xpos + 1);
-
- }
-
-
- /* general drawing routines */
-
- emprep()
- {
- if (emwindow == NULL)
- return;
-
- ++inemulator;
-
- if (emdp->dsdraw && !bkrd_act && dsdrawok()) {
- /* set the flag to show everything is ok to use dsdraw */
- usedsdraw = TRUE;
- }
- else {
- usedsdraw = FALSE;
- }
- if (usedsdraw && mousecurson) {
- ShieldCursor(&emdp->zaprect, 0L);
- /* long not really legit: pass(Point(0,0)) or pass(topLeft(emwindow->portRect)) */
- /* HideCursor(); */
- mousecurson = FALSE;
- }
-
- if (updatewait()) {
- /* do nothing if an update is pending */
- /* TODO what about updatewait() ? does it need to be called
- intermittently to keep screen posters
- such as QuickMail Conferencing from producing turds? */
-
- emupdwait = TRUE;
- usedsdraw = FALSE; /* make sure chars don't appear promptly */
- }
- else {
- emupdwait = FALSE;
- if (emdp->curson) {
- /* if cursor visible, invert it */
- InvertRect(&emdp->cursrect);
- emdp->curson = FALSE;
- }
- if (trackon && emdp == keydp) {
- InvertRect(&mouserect);
- trackon = FALSE;
- }
- }
- emtestvis();
- }
-
- emend()
- {
- if (emwindow == NULL)
- return;
-
- --inemulator;
- if (usedsdraw) {
- if (!mousecurson) {
- /* if (!mfbackground)
- ObscureCursor();
- hide until next motion; incompatible with ShieldCursor */
- ShowCursor();
- mousecurson = TRUE;
- }
- }
- else if (!mousecurson) {
- ShowCursor();
- mousecurson = TRUE;
- }
- }
-
-
- /* drawing routines for direct-to-screen algorithm */
-
- /*
- * Redraw the window frame screen contents from the screen map in charr[]
- * (called on updateEvt)
- *
- */
-
-
- emrefresh(emwindow, doinvert)
- WindowPtr emwindow;
- short doinvert;
- {
- register unsigned char * chp;
- register unsigned char * attp;
- register unsigned char curattr;
- register short notstart; /* # chars to start of invert range */
- register short notcount; /* # chars within invert range */
- register unsigned long linemod;
- register unsigned long lineclr;
- short oldx, oldy;
- FONTS *oldfont;
- GrafPtr oldport;
- char zapped = FALSE;
- short textmode; /* current text mode */
- short ozapinvert;
- short ozapuline;
-
- if (emwindow == NULL)
- return;
-
- if (bkrd_act || !dsdrawok()) {
- paintbuf(&emdp->charr[0], doinvert);
- return;
- }
-
- GetPort(&oldport);
- SetPort(emwindow);
-
- inselection = FALSE;
- ozapinvert = zapinvert; /* save current state */
- ozapuline = zapuline;
- if (doinvert) {
- if (emdp->selrectvis) {
- /* calculate character range over which we use notSrcCopy */
- notstart = emdp->selystart * linelength + emdp->selxstart;
- notcount = emdp->selyend * linelength + emdp->selxend - notstart;
- if (notcount == 0) {
- doinvert = FALSE;
- }
- else if (notstart == 0)
- inselection = TRUE;
- }
- else
- doinvert = FALSE;
- }
-
- oldx = xpos;
- oldy = ypos;
- oldfont = thefont;
-
- /* fill screen */
- chp = emdp->charr;
- attp = chp + emdp->screensize;
- curattr = TRUE; /* force attr set on first round */
-
- /* xpos & ypos need to be set for zapchar */
- for (ypos = 0; ypos <= emdp->lastrow; ++ypos) {
- linemod = modflg & modmask[ypos];
- lineclr = clrflg & modmask[ypos];
- for (xpos = 0; xpos <= lastcol; ++xpos, ++chp, ++attp) {
- if (doinvert) {
- /* check to see if we're in the selection range */
- if (notstart-- == 0) {
- /* we just entered the range */
- curattr = TRUE;
- /* we presume no attr can be all TRUE */
- inselection = TRUE;
- }
- if (notstart < 0) {
- /* we have entered the range */
- if (notcount-- == 0) {
- /* we just left it */
- curattr = TRUE;
- doinvert = FALSE;
- inselection = FALSE;
- }
- }
- }
- if (!linemod)
- /* no need to check attributes or draw if line not modified */
- continue;
-
- if (*attp != curattr) {
- curattr = *attp;
-
- /* set the font display mode */
- setascattr_ds(curattr, inselection);
- }
- if (lineclr && skiparr[*chp] && !zapuline && !zapinvert)
- /* we don't need to draw blanks */
- continue;
-
- zapchar(*chp);
- zapped = TRUE;
- }
- if (zapped) {
- clrflg &= ~modmask[ypos]; /* reset clear flag */
- zapped = FALSE;
- }
- }
-
- /* reset font */
- zapinvert = ozapinvert;
- zapuline = ozapuline;
- thefont = oldfont;
- xpos = oldx;
- ypos = oldy;
-
- modflg = 0;
- SetPort(oldport);
- }
-
-
- /* scroll the screen image */
-
- scrollup_ds()
- {
- struct winds * owp;
- EventRecord anevent;
-
- if (bkrd_act || !dsdrawok()) {
- /* use QD scroll call before logsession etc. */
-
- scrollup_qd();
- return;
- }
-
- #ifdef SUICIDAL
- /* the background service stuff here is very dangerous... */
- /* check to see if user wants to stop */
- if (emdp->scrollcount++ > 8) {
- owp = emdp;
-
- emdp->scrollcount = 0;
- ++bkrd_act;
- do {
- /* TODO should call bkrd_service && block out current window??? */
- user_act();
- maccursor(TRUE); /* move the cursor without tracking in emulator */
- }
- while (emdp->userxoff);
- if (bkrd_act > 0)
- --bkrd_act;
- getcontext(owp);
- /* restore the old context, will fix port after maccursor */
-
- /* scrolling up yields, make sure dsdraw still valid */
- if (emdp->dsdraw && !bkrd_act && dsdrawok()) {
- usedsdraw = TRUE;
- }
- else {
- usedsdraw = FALSE;
- }
- if (usedsdraw) {
- /* could be we're behind something now... */
- scrollup_qd();
- return;
- }
- }
- #else
- /* user has sent ^S; hang until keystroke or mouseclik */
- if (emdp->userxoff) {
- while (TRUE) {
- if (EventAvail(keyDownMask | mDownMask, &anevent))
- break;
- }
- }
-
- #endif
- if (emwindow != NULL) {
- /* update the screen */
- if (emdp->vtjumpscroll || emupdwait) {
- /* wait to draw the screen */
- modflg = SCRALLMOD;
- }
- else if (emdp->selrectvis) {
- /* don't scroll the selection, redraw the whole screen using ds update */
- modflg = SCRALLMOD;
- }
- else {
- /* erase the cursor, which won't be picked up by scroll routine */
- if (emdp->curson) {
- InvertRect(&emdp->cursrect);
- emdp->curson = FALSE;
- }
- if (modflg) {
- /* update before scroll */
- emrefresh(emwindow, TRUE);
- }
- modflg >>= 1; /* shift modified flags right */
- clrflg >>= 1; /* shift clear flags right */
- clrflg |= modmask[emdp->lastrow]; /* show line cleared at bottom */
-
- fastscroll(startarr[0], startarr[1], emdp->lastrow);
- }
- }
- saveline(&emdp->charr[0], linelength);
- /* save the line if needed before it gets overwritten */
-
- /* take care of screen map */
- BlockMove(emdp->secondline, &emdp->charr[0], emdp->size23);
- BlockMove(emdp->secondline + emdp->screensize, &emdp->charr[0] + emdp->screensize, emdp->size23);
- c19_blank(emdp->lastline, linelength);
-
- if (emwindow && emdp->selrectvis) {
- /* display the updated screen promptly */
- emrefresh(emwindow, TRUE);
- }
-
- return(0);
- }
-
-
-
- /* quickdraw version of the drawing routines */
-
- paintbuf(scrbuf, doinvert)
- unsigned char * scrbuf;
- short doinvert;
- {
- register unsigned char * textp;
- register unsigned char * drawstart;
- register unsigned char * lineend;
- register unsigned char * attp;
- register unsigned char attr;
- register short notstart; /* # chars to start of invert range */
- register short notcount; /* # chars within invert range */
- #ifdef SKIPBLANKS
- register short blanks = 0; /* # blanks not to draw */
- #endif
- register unsigned long linemod;
- register unsigned long lineclr;
-
- short drawcount;
- char zapped = FALSE;
-
- short yloc;
- short linecount;
- unsigned char inselection; /* in selection range */
- short textmode; /* current text mode */
-
-
- if (emwindow == NULL)
- return;
-
- yloc = emdp->lineheight - emdp->fontdescent + emdp->voffset; /* pen vert pos */
- textp = drawstart = scrbuf;
-
- /* find and set current attribute */
- attp = scrbuf + emdp->screensize;
- attr = *attp;
-
- inselection = FALSE;
- if (doinvert) {
- if (emdp->selrectvis) {
- /* calculate character range over which we use notSrcCopy */
- notstart = emdp->selystart * linelength + emdp->selxstart;
- notcount = emdp->selyend * linelength + emdp->selxend - notstart;
- if (notcount == 0) {
- doinvert = FALSE;
- }
- else if (notstart == 0)
- inselection = TRUE;
- }
- else
- doinvert = FALSE;
- }
- attr = TRUE; /* force attribute setting first time around */
-
- lineend = textp + linelength;
- for (linecount = 0; linecount <= emdp->lastrow; linecount++, lineend += linelength) {
- linemod = modflg & modmask[linecount];
- lineclr = clrflg & modmask[linecount];
-
- if (linemod)
- MoveTo(emdp->hoffset, yloc);
- for ( ; textp < lineend; textp++, attp++) {
- if (doinvert) {
- /* check to see if we're in the selection range */
- if (notstart-- == 0) {
- /* we just entered the range */
- attr = TRUE;
- inselection = TRUE;
- }
- if (notstart < 0) {
- /* we have entered the range */
- if (notcount-- == 0) {
- /* we just left it */
- inselection = FALSE;
- attr = TRUE;
- doinvert = FALSE;
- }
- }
- }
- if (! linemod) {
- /* no need to check attributes if we're not drawing */
- continue;
- }
- if (*attp != attr) {
- /* we hit a new attribute, draw a string now */
-
- #ifdef SKIPBLANKS
- drawcount = textp - drawstart - blanks;
- if (drawcount > 0) {
- DrawText(drawstart, 0, drawcount);
- zapped = TRUE;
- }
- if (blanks) {
- /* skip them */
- Move(blanks * fontwidth, 0);
- blanks = 0;
- }
- #else
- DrawText(drawstart, 0, textp - drawstart);
- #endif
- drawstart = textp;
- if (attr == TRUE) {
- /* could be transiting selection range, set new mode & reset flag */
- if (notstart == -1) {
- /* just entered the range */
- inselection = TRUE;
- }
- else if (notcount == -1) {
- inselection = FALSE;
- }
- }
-
- /* set the font type */
- attr = *attp;
- textmode = setascattr_qd(attr, inselection);
- }
- #ifdef SKIPBLANKS
- if (!emdp->color && lineclr) {
- if (skiparr[*textp] && textmode == srcCopy) {
- /* add up consecutive blanks at right end */
- blanks++;
- }
- else if (blanks > 2) {
- /* we'll break up line into smaller frags but will skip more
- spaces, an OK trade? */
- --textp; /* back up to catch this char again */
- --attp;
- attr = TRUE;
- }
- else
- blanks = 0;
- }
- #endif
- }
- if (linemod && drawstart < lineend) {
- /* avoid problems with attribute at end of line */
- drawcount = textp - drawstart - blanks;
- if (drawcount > 0) {
- DrawText(drawstart, 0, drawcount);
- zapped = TRUE;
- }
- }
- if (zapped) {
- clrflg &= ~modmask[linecount]; /* reset clear flag */
- zapped = FALSE;
- }
- blanks = 0;
- drawstart = lineend;
- yloc += emdp->lineheight;
- /* fix for the next time around */
- }
- TextMode(srcCopy);
- TextFace(0); /* return to normal font style */
- modflg = 0;
- }
-
-
- /* quickdraw routine to draw a character on the screen */
-
- ch_draw_qd(thechar)
- register char thechar;
- {
- short offset;
- short oldfont;
- GrafPtr oldport;
- short notstart, notcount, thispos;
- char inselection;
- Rect chinvrect;
-
- if (emwindow == NULL)
- return;
-
- GetPort(&oldport);
- SetPort(emwindow);
-
- oldfont = emwindow->txFont;
-
- inselection = chkinvert();
-
- TextSize(emdp->fontsize);
-
- setascattr_qd(attrib, inselection);
-
- /* do it */
-
- chinvrect.top = ypos * emdp->lineheight + emdp->voffset;
- chinvrect.left = xpos * fontwidth + emdp->hoffset;
-
- MoveTo(chinvrect.left, chinvrect.top + emdp->lineheight - emdp->fontdescent);
- DrawChar(thechar);
-
- /* endibmdraw_qd(); */
-
- if (inselection) {
- if (emdp->color) {
- /* invert the newly drawn character */
- chinvrect.bottom = chinvrect.top + emdp->fontheight; /* - 2 skipped by zap */
- chinvrect.right = chinvrect.left + emdp->fontwidth;
-
- InvertRect(&chinvrect);
- }
- else
- TextMode(srcCopy);
- }
- TextFace(0);
- TextFont(oldfont);
- SetPort(oldport);
- if (emdp->color) {
- BackColor((long) whiteColor);
- ForeColor((long) blackColor);
- }
- }
-
-
- /* A portable routine to scroll up the emulator screen up one line,
- as fast as possible
- */
-
- scrollup_qd()
- {
- short bigsave;
- RgnHandle oldclip;
- struct winds * owp;
- EventRecord anevent;
-
- #ifdef SUICIDAL
- /* the background service stuff here is very dangerous... */
- /* check to see if user wants to stop */
- if (emdp->scrollcount++ > 8) {
- emdp->scrollcount = 0;
- ++bkrd_act;
- owp = emdp;
- do {
- user_act();
- maccursor(TRUE); /* move the cursor without tracking in emulator */
- }
- while (emdp->userxoff);
- if (bkrd_act > 0)
- --bkrd_act;
- getcontext(owp);
- /* restore the old context */
- }
- #else
- /* user has sent ^S; hang until keystroke or mouseclik */
- if (emdp->userxoff) {
- while (TRUE) {
- if (EventAvail(keyDownMask | mDownMask, &anevent))
- break;
- }
- }
-
- #endif
-
- if (emwindow != NULL && modflg &&
- !(emdp->vtjumpscroll || emdp->selrectvis || bkrd_act || emupdwait || emobscured)) {
- /* we're using QD & buffer's changed, update screen before ScrollRect */
- (*emdp->screen_upd)();
- }
-
- saveline(&emdp->charr[0], linelength);
- /* save the line if needed before it gets overwritten */
-
- /* take care of screen map */
- BlockMove(emdp->secondline, &emdp->charr[0], emdp->size23);
- BlockMove(emdp->secondline + emdp->screensize, &emdp->charr[0] + emdp->screensize, emdp->size23);
- c19_blank(emdp->lastline, linelength);
-
- if (emwindow == NULL)
- return;
-
- /* scroll the screen image */
- if (emupdwait || emdp->vtjumpscroll) {
- /* redraw the whole screen later on */
- modflg = SCRALLMOD;
- }
- else if (emdp->selrectvis || bkrd_act || emobscured) {
- /* redraw the whole screen using QD || emdp->color */
- modflg = SCRALLMOD;
- (*emdp->screen_upd)();
- }
- #ifdef THISWORKS
- /* alas, this doesn't work; seems to mess things up for some reason */
- else if (bkrd_act) {
- /* ought to scroll & redraw the just updateRgn using QD */
- /* reset clip to area we're drawing in */
- oldclip = NewRgn();
- GetClip(oldclip);
-
- modflg >>= 1; /* shift modified flags right */
- clrflg >>= 1; /* shift clear flags right */
- ScrollRect(&emdp->bigrect, 0, -emdp->lineheight, updateRgn);
- clrflg |= modmask[emdp->lastrow]; /* show line cleared at bottom */
-
- SetClip(updateRgn);
-
- modflg = SCRALLMOD;
- (*emdp->screen_upd)();
-
- SetClip(oldclip);
- DisposeRgn(oldclip);
- }
- #endif
- else {
- modflg >>= 1; /* shift modified flags right */
- clrflg >>= 1; /* shift clear flags right */
- clrflg |= modmask[emdp->lastrow]; /* show line cleared at bottom */
-
- ScrollRect(&emdp->bigrect, 0, -emdp->lineheight, updateRgn);
- if (emdp->color) {
- paintupdate();
- }
- }
- }
-
- #define ATNORM 0
- #define ATNORMREV 2
- #define ATBOLD 4
- #define ATBOLDREV 6
-
- #define ATBLINK 8
-
- #define ATFORE 0
- #define ATBACK 1
-
- setascattr_qd(attrib, inselection)
- unsigned char attrib;
- int inselection;
- {
- int textmode; /* drawing mode of pen */
- int field = ATNORM;
-
- if (emwindow == NULL)
- return;
-
- #ifndef MERGEDVTCHARS
- /* set the font type */
- if (attrib & VTFONT)
- TextFont(emdp->vtfont);
- else
- #endif
- TextFont(emdp->normfont);
-
- /* set the font display mode */
- TextFace(0);
- textmode = (inselection ? notSrcCopy : srcCopy);
-
- if (attrib & REVERSE) {
- textmode = (inselection ? srcCopy : notSrcCopy);
- /* in selection range, reversed reverse! */
-
- if (!inselection)
- /* make the field a reverse color */
- field = ATNORMREV;
- }
- if (attrib & UNDERSCORE) {
- TextFace(underlineStyle);
- }
- if (attrib & BLINK) {
- /* only works in color */
- field += ATBLINK;
- }
- if (attrib & BOLD) {
- field += ATBOLD;
- #ifndef MERGEDVTCHARS
- if (! (attrib & VTFONT))
- #endif
- TextFont(emdp->highfont);
- }
- if (emdp->color) {
- RGBForeColor(&emdp->colormap.colors[field]);
- RGBBackColor(&emdp->colormap.colors[field + ATBACK]);
- }
- else
- TextMode(textmode);
-
- return(textmode);
- }
-
-
- paintupdate()
- {
- /* fill in the new space with the norm bkrd color */
- RGBColor forecolor;
-
- if (usedsdraw)
- return;
-
- GetForeColor(&forecolor);
-
- RGBForeColor(&emdp->colormap.colors[1]); /* normal background */
- PaintRect(&((*updateRgn)->rgnBBox));
- RGBForeColor(&forecolor);
- }
-
-
- /* just in case BlockMove doesn't work ..... */
-
- myBlockMove(source, dest, length)
- char * source;
- char * dest;
- long length;
- {
- length++;
- if (source > dest) {
- while (--length) {
- *dest++ = *source++;
- }
- }
- else {
- /* make sure overlapping block handled OK */
- source += length;
- dest += length;
- while (--length) {
- *--dest = *--source;
- }
- }
- }
-
-
- /* set the direct to screen font * to reflect the current attribute */
-
- setascattr_ds(attrib, inselection)
- register unsigned char attrib;
- register short inselection;
- {
-
- if (emdp->dsdraw) {
- #ifndef MERGEDVTCHARS
- if (attrib & VTFONT) {
- /* doesn't handle bold */
- if (attrib & REVERSE) {
- thefont = (inselection ? &bvtfont : &invbvtfont);
- /* in selection range, reversed reverse! */
- }
- else
- thefont = (inselection ? &invbvtfont : &bvtfont);
- }
- else
- #endif
- {
- if (attrib & REVERSE) {
- /* in selection range, reversed reverse! */
- if (attrib & BOLD) {
- thefont = (inselection ? &boldfont : &invboldfont);
- }
- else {
- thefont = (inselection ? &font : &invfont);
- }
- }
- else if (attrib & BOLD) {
- thefont = (inselection ? &invboldfont : &boldfont);
- }
- else
- thefont = (inselection ? &invfont : &font);
- }
- if (attrib & UNDERSCORE) {
- zapuline = TRUE;
- }
- else {
- zapuline = FALSE;
- }
- if (thefont == &invfont
- || thefont == &invboldfont
- #ifndef MERGEDVTCHARS
- || thefont == &invbvtfont
- #endif
- )
- zapinvert = TRUE;
- else
- zapinvert = FALSE;
- #ifdef BITSUPPORT
- if (attrib & BLINK) {
- /* ??? what should be done ? */
- TextMode(inselection ? srcCopy : notSrcCopy);
- }
- #endif
- }
- }
-
-
- /* clear a rectangle, paint the background if colored */
-
- clearrect(rectp)
- Rect * rectp;
- {
- RGBColor forecolor;
-
- #ifdef PROMPTUPD
- if (modflg) {
- /* we're using QD & buffer's changed, update screen first */
- if (usedsdraw)
- emrefresh(emwindow, TRUE);
- else
- (*emdp->screen_upd)();
- }
- #endif
- if (emdp->color) {
- GetForeColor(&forecolor);
-
- RGBForeColor(&emdp->colormap.colors[1]); /* normal background */
- PaintRect(rectp);
- RGBForeColor(&forecolor);
- }
- else {
- EraseRect(rectp);
- }
- }
-
-
- /* check the visible region of the window to see whether other windows
- overlap, which means we must refresh entire screen */
-
- emtestvis()
- {
- Rect intersect;
- RgnPtr visptr = (*emwindow->visRgn);
-
- if (emwindow == FrontWindow() &&
- (emdp->gdRect.bottom == 342)
- || (emdp->fontsize == 16 && emdp->gdRect.bottom == 480)
- ) {
- /* we're on a small screen & the emulator area is completely visible;
- on small screens it will be vis since not movable,
- but there's a real rgn due to the round corners added
- by the stupid screen interface so the following test will fail.... */
- emobscured = FALSE;
- }
- else if (visptr->rgnSize == 10
- && SectRect(&emdp->bigrect, &visptr->rgnBBox, &intersect)
- && EqualRect(&emdp->bigrect, &intersect)) {
- /* the emulator area is completely visible */
- emobscured = FALSE;
- }
- else
- emobscured = TRUE;
- }